﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhDataAcess.produceDAL;
using dhSystemBLL.produceBLL;
using dhSystemBLL.orderData;
using dhDataAcess.produceLinq;
using dhDataAcess.baseBLL;
using baseSet.importExport;

namespace dhsystem.produceForm
{
    public partial class FrmorderStockOutDetailAdd : Form
    {
        orderStockOutBLL orderStockOut = new orderStockOutBLL();
        orderStockOutDetailModel orderStockOutDetailRow = new orderStockOutDetailModel();
        productListBLL product = new productListBLL();
        orderDetailBLL orderDetail = new orderDetailBLL();
        BindingSource BindingSourceorderStockOutDetailAdd;
        string state;
        string billNo;
        //绑定数据源
        public FrmorderStockOutDetailAdd(BindingSource bindingSourceorderStockOutDetail, string _state, string _billNo)
        {
            InitializeComponent();
            BindingSourceorderStockOutDetailAdd = bindingSourceorderStockOutDetail;
            state = _state;
            billNo = _billNo;
        }
        //打开窗口时绑定数据
        private void FrmorderStockOutDetailAdd_Load(object sender, EventArgs e)
        {
            //bindingSourceproductList.DataSource = product.getproductListAll();
            //comboBoxpName.DataSource = bindingSourceproductList;
            //comboBoxpName.DisplayMember = "pname";
            //comboBoxpName.ValueMember = "pname";
            //bindingSourceorderDetail.DataSource = orderDetail.getorderDetailAll();
            //comboBoxorderDetailNo.DataSource = bindingSourceorderDetail;
            //comboBoxorderDetailNo.DisplayMember = "orderDetailNo";
            //comboBoxorderDetailNo.ValueMember = "orderDetailNo";

            if (state == "编辑")
            {
                textbillNo.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "billNo");
                textpname.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "pName");
                textorderDetailNo.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "orderDetailNo");
                textqty.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "qty");
                textunit.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "unit");
                textboxno.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "boxno");
                textboxList.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "boxList");
                textweightJ.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "weightJ");
                textweightM.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "weightM");
                textmark.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "mark");
                //textid.DataBindings.Add("text", BindingSourcescrlDetailAdd, "recordid");
                // BindingSourceDetailAdd.AddNew();
                //textproductname.Text = productname;
            }
            if (state == "新增")
            {
                textbillNo.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "billNo");
                textpname.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "pName");
                textorderDetailNo.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "orderDetailNo");
                textqty.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "qty");
                textunit.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "unit");
                textboxno.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "boxno");
                textboxList.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "boxList");
                textweightJ.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "weightJ");
                textweightM.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "weightM");
                textmark.DataBindings.Add("text", BindingSourceorderStockOutDetailAdd, "mark");
                // textid.DataBindings.Add("text", BindingSourcescrlDetailAdd, "recordid");
                BindingSourceorderStockOutDetailAdd.AddNew();
                textbillNo.Text = billNo;
            }

            textqty.Focus();
        }
        //保存按钮，插入或修改数据
        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("是否保存资料！", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {

                    BindingSourceorderStockOutDetailAdd.EndEdit(); //编辑到完成，写到数据源
                    BindingSourceorderStockOutDetailAdd.CancelEdit(); //刷新数据作用

                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        //取消按钮
        private void buttonCancel_Click(object sender, EventArgs e)
        {

            BindingSourceorderStockOutDetailAdd.CancelEdit();
            this.Close();
        }

        private void buttworkerselect_Click(object sender, EventArgs e)
        {
            string field;
            field = "orderDetailNo";
            Frmprodutselect productselect = new Frmprodutselect(moduleInfo.orderDetail, field);
            DialogResult result = productselect.ShowDialog();
            if (result == DialogResult.Yes)
            {
                textorderDetailNo.Text = productselect.pname;
            }
        }
        //选择漂染单号时候发生的事件
        private void textorderDetailNo_TextChanged(object sender, EventArgs e)
        {
            try
            {
              textpname .Text =  basicSql.getpnamebyorderDetail(textorderDetailNo.Text);
              textunit .Text =  basicSql.getunitbyorderDetail(textorderDetailNo.Text);
              textqty.Text = basicSql.getqtybyorderDetail(textorderDetailNo.Text);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
    }
}
